package com.heg.bk.control;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.heg.bk.entity.HegSysUser;
import com.heg.bk.service.SystemManagerService;

/**
 * 系统用户管理控制层
 * @author dengxuzhoa
 * @time 2016-04-19
 * @version 1.0.1
 */
@RequestMapping(value = "/hegbk/sysmana")
@Controller("systemManagerAction")
public class SystemManagerAction {
	
	@Resource
	private SystemManagerService systemManagerService;
	
	@RequestMapping(value = "/login", method = RequestMethod.POST)
	public String bk_user_login(Model model, HttpServletRequest request,
			@RequestParam(value = "uname", required = true) String uname,
			@RequestParam(value = "pword", required = true) String pword){
		List lst =  systemManagerService.sel_bkLogin(uname, pword);
		if(lst != null && lst.size() > 0){
			HegSysUser hegSysUser = (HegSysUser) lst.get(0);
			model.addAttribute("sysuser", hegSysUser);
			//登录成功后保存到session
			request.getSession().setAttribute("sysUser", hegSysUser);
			return "html/bk-index"; 
		} else {
			return "html/bk-login"; 
		}
	}
	
	@RequestMapping(value = "/dropout", method = RequestMethod.GET)
	public String bk_user_drop_outlogin(HttpServletRequest request){
		request.getSession().removeAttribute("sysuser");
		return "/html/bk-login";
	}

}
